import { ref } from 'vue';
import { getAccountsPayableHistoryApi } from '@/api/sj/financialManagement/accountsPayable'
import { getBadDebtHistoryApi } from '@/api/sj/financialManagement/accountsReceivable/index';

const useHistoryRecords = () => {

    const historyRecordsVisible = ref(false);
    const historyRecordsType = ref(1);

    /** 打开 平账历史记录 弹窗 */
    const hanleOpenBalancingAccounts = async (type: number) => {
        getHistoryRecordsList();
        historyRecordsType.value = type;
        historyRecordsVisible.value = true;
    };


    /** 平账历史记录 */
    const historyRecordsList = ref([]);
    const getHistoryRecordsList = async () => {
        const {data} = await getAccountsPayableHistoryApi();
        historyRecordsList.value = data;
    };

    /** 打开坏账记录 弹窗 */
    const hanleOpenBadDebt = async () => {
        getBadDebtList();
        historyRecordsVisible.value = true;
    };
    
    /** 获取坏账记录 */
    const getBadDebtList = async () => {
        const {data} = await getBadDebtHistoryApi();
        historyRecordsList.value = data;
    };

    return {
        historyRecordsVisible,
        historyRecordsType,
        historyRecordsList,
        hanleOpenBadDebt,
        hanleOpenBalancingAccounts,
    }
};

export default useHistoryRecords;
